package com.rykj.qxj.server.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rykj.qxj.server.dao.RuleMapper;
import com.rykj.qxj.server.model.entity.Rule;
import com.rykj.qxj.server.services.IRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("ruleService")
public class RuleServiceImpl implements IRuleService {
    @Autowired
    private RuleMapper ruleMapper;

    @Override
    public void saveRule(Rule feildRule) {
        ruleMapper.saveRule(feildRule);
    }

    @Override
    public void updateRule(Rule feildRule) {
        ruleMapper.updateRule(feildRule);
    }

    @Override
    public void deleteRule(Integer id) {
        ruleMapper.deleteRule(id);
    }

    @Override
    public Rule getRuleDetails(Integer id) {
        return  ruleMapper.getRuleDetails(id);

    }

    @Override
    public PageInfo getRuleList(Integer pageNum, Integer pageSize, String ruleID, String ruleName) {
        PageHelper.startPage(pageNum,pageSize);
        Map<String,Object> paraMap = new HashMap<>();
        if("%".equals(ruleName)){
            ruleName ="\\%";
        }
        paraMap.put("ruleID",ruleID);
        paraMap.put("ruleName",ruleName);
        List<Rule> feildRules =  ruleMapper.getRuleList(paraMap);
        PageInfo pageInfo = new PageInfo(feildRules);
        return  pageInfo;
    }
}
